home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-desktop-9.10-i386-PL.iso / casper / filesystem.squashfs / usr / share / hplip / ui4 / printdialog.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2009-10-28  |  6KB  |  156 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. from base.g import *
  5. from base import device, utils
  6. from prnt import cups
  7. from base.codes import *
  8. from ui_utils import *
  9. from PyQt4.QtCore import *
  10. from PyQt4.QtGui import *
  11. from printdialog_base import Ui_Dialog
  12. from filetable import FileTable, FILETABLE_TYPE_PRINT
  13. from printernamecombobox import PRINTERNAMECOMBOBOX_TYPE_PRINTER_ONLY
  14. PAGE_FILE = 0
  15. PAGE_OPTIONS = 1
  16. PAGE_MAX = 1
  17.  
  18. class PrintDialog(QDialog, Ui_Dialog):
  19.     
  20.     def __init__(self, parent, printer_name, args = None):
  21.         QDialog.__init__(self, parent)
  22.         self.setupUi(self)
  23.         self.printer_name = printer_name
  24.         self.user_settings = UserSettings()
  25.         self.user_settings.load()
  26.         self.user_settings.debug()
  27.         self.initUi()
  28.         self.file_list = []
  29.         if args is not None:
  30.             for a in args:
  31.                 self.Files.addFileFromUI(os.path.abspath(a))
  32.             
  33.         
  34.         self.devices = { }
  35.         QTimer.singleShot(0, self.updateFilePage)
  36.  
  37.     
  38.     def initUi(self):
  39.         self.OptionsToolBox.include_job_options = True
  40.         self.connect(self.CancelButton, SIGNAL('clicked()'), self.CancelButton_clicked)
  41.         self.connect(self.BackButton, SIGNAL('clicked()'), self.BackButton_clicked)
  42.         self.connect(self.NextButton, SIGNAL('clicked()'), self.NextButton_clicked)
  43.         self.initFilePage()
  44.         self.initOptionsPage()
  45.         self.setWindowIcon(QIcon(load_pixmap('hp_logo', '128x128')))
  46.         if self.printer_name:
  47.             self.PrinterName.setInitialPrinter(self.printer_name)
  48.         
  49.         self.StackedWidget.setCurrentIndex(0)
  50.  
  51.     
  52.     def initFilePage(self):
  53.         self.Files.setType(FILETABLE_TYPE_PRINT)
  54.         self.Files.setWorkingDir(self.user_settings.working_dir)
  55.         self.connect(self.Files, SIGNAL('isEmpty'), self.Files_isEmpty)
  56.         self.connect(self.Files, SIGNAL('isNotEmpty'), self.Files_isNotEmpty)
  57.  
  58.     
  59.     def updateFilePage(self):
  60.         self.NextButton.setText(self._PrintDialog__tr('Next >'))
  61.         self.NextButton.setEnabled(self.Files.isNotEmpty())
  62.         self.BackButton.setEnabled(False)
  63.         self.updateStepText(PAGE_FILE)
  64.         self.Files.updateUi()
  65.  
  66.     
  67.     def Files_isEmpty(self):
  68.         self.NextButton.setEnabled(False)
  69.  
  70.     
  71.     def Files_isNotEmpty(self):
  72.         self.NextButton.setEnabled(True)
  73.  
  74.     
  75.     def initOptionsPage(self):
  76.         self.BackButton.setEnabled(True)
  77.         self.PrinterName.setType(PRINTERNAMECOMBOBOX_TYPE_PRINTER_ONLY)
  78.         self.connect(self.PrinterName, SIGNAL('PrinterNameComboBox_currentChanged'), self.PrinterNameComboBox_currentChanged)
  79.         self.connect(self.PrinterName, SIGNAL('PrinterNameComboBox_noPrinters'), self.PrinterNameComboBox_noPrinters)
  80.  
  81.     
  82.     def updateOptionsPage(self):
  83.         QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
  84.         
  85.         try:
  86.             self.PrinterName.updateUi()
  87.             self.BackButton.setEnabled(True)
  88.             num_files = len(self.Files.file_list)
  89.             if num_files > 1:
  90.                 self.NextButton.setText(self._PrintDialog__tr('Print %1 Files').arg(num_files))
  91.             else:
  92.                 self.NextButton.setText(self._PrintDialog__tr('Print File'))
  93.             self.updateStepText(PAGE_OPTIONS)
  94.         finally:
  95.             QApplication.restoreOverrideCursor()
  96.  
  97.  
  98.     
  99.     def PrinterNameComboBox_currentChanged(self, device_uri, printer_name):
  100.         
  101.         try:
  102.             self.devices[device_uri]
  103.         except KeyError:
  104.             self.devices[device_uri] = device.Device(device_uri)
  105.  
  106.         self.OptionsToolBox.updateUi(self.devices[device_uri], printer_name)
  107.  
  108.     
  109.     def PrinterNameComboBox_noPrinters(self):
  110.         FailureUI(self, self._PrintDialog__tr('<b>No printers found.</b><p>Please setup a printer and try again.'))
  111.         self.close()
  112.  
  113.     
  114.     def executePrint(self):
  115.         for cmd in self.OptionsToolBox.getPrintCommands(self.Files.file_list):
  116.             log.debug(cmd)
  117.             (status, output) = utils.run(cmd, log_output = True, password_func = None, timeout = 1)
  118.             if status != 0:
  119.                 FailureUI(self, self._PrintDialog__tr('<b>Print command failed with status code %1.</b><p>%2</p>').arg(status).arg(cmd))
  120.                 continue
  121.         
  122.         self.close()
  123.  
  124.     
  125.     def CancelButton_clicked(self):
  126.         self.close()
  127.  
  128.     
  129.     def BackButton_clicked(self):
  130.         p = self.StackedWidget.currentIndex()
  131.         if p == PAGE_OPTIONS:
  132.             self.StackedWidget.setCurrentIndex(PAGE_FILE)
  133.             self.updateFilePage()
  134.         else:
  135.             log.error('Invalid page!')
  136.  
  137.     
  138.     def NextButton_clicked(self):
  139.         p = self.StackedWidget.currentIndex()
  140.         if p == PAGE_FILE:
  141.             self.StackedWidget.setCurrentIndex(PAGE_OPTIONS)
  142.             self.updateOptionsPage()
  143.         elif p == PAGE_OPTIONS:
  144.             self.executePrint()
  145.         
  146.  
  147.     
  148.     def updateStepText(self, p):
  149.         self.StepText.setText(self._PrintDialog__tr('Step %1 of %2').arg(p + 1).arg(PAGE_MAX + 1))
  150.  
  151.     
  152.     def __tr(self, s, c = None):
  153.         return qApp.translate('PrintDialog', s, c)
  154.  
  155.  
  156.